package gnss

var (
	//[7,6,5,4] = Signal ID (L1CA, L5, G1, B1I, B2I, B3I, etc)
	// GPS Signal ID: L1CA=0, L2P=1, L2C=2, L5=3
	// GLO Signal ID: G1C/G1P=0, G2C/G2P=1, G10C=4, G20C=5, G30C=6
	// GAL Signal ID: E1BC=0, E5A=1, E5B=2, E6=3, ALTBOC=4
	// BDS Signal ID: B1I=0, B2I=1, B3I=2,B1BOC=3,B2A=4,B2B=5,B3C=6,ACEBOC=7
	// QZS Signal ID: L1CA=0, L2C=2, L5=3, L1C=4

	//YOBS_BDS_SIGN_MAP = []string{
	//	"",               // 1
	//	"2I", "2Q", "2X", // 2, 3,4       (B1)
	//	"1D", "1P", "1X", // 5, 6, 7      (B1C) RINEX文档中, 但是没有具体编号
	//	"6I", "6Q", "6X", // 8, 9, 10     (B3)
	//	"", "", "", // 11-13
	//	"7I", "7Q", "7X", // 14, 15, 16   (B2)
	//	"5D", "5P", "5X", // 17, 18, 19   (B2a)
	//	"7D", "7P", "7Z", // 20, 21, 22   (B2b)
	//	"8D", "8P", "8X", // 23, 24, 25   (B2a + B2b)
	//	"1A", "1B", "1C", // 26, 27, 28   (B1C)   // RINEX中没有
	//	"",
	//	"1D", "1P", "1X", // 30, 31, 32   (B1C)   // RINEX中没有
	//
	//}

	// BDS Signal ID:
	//    B1I=2I,
	//    B2I=7I,
	//    B3I=6I,
	//    B1BOC=1P,
	//    B2A=5P,  5D
	//    B2B=7P,  7D
	//    B3C=预留,
	//    ACEBOC=8P
	//
	HEMI_BDS_SIGN_YOBS_MAP = []byte{YOBS_BDS_SIGN_B1_2I, YOBS_BDS_SIGN_B2_7I, YOBS_BDS_SIGN_B3_6I, YOBS_BDS_SIGN_B1C_1P,
		YOBS_BDS_SIGN_B2A_5D, YOBS_BDS_SIGN_B2B_7D, 0, YOBS_BDS_SIGN_B2AB_8P}

	/*
			YOBS_GAL_SIGN_MAP = []string{"",
				"1C", "1A", "1B", // 2-4    E1
				"1X", "1Z",  "",    // 5,6,7        E1
				"6C", "6A", "6B",  // 8,9,10    E6
				"6X", "6Z", "",    // 11,12,13
				"7I", "7Q", "7X",  // 14-16     // E5B
				"",                // 17
				"8I", "8Q", "8X",  // 18-20    // E5(A+B)
				"",                // 21
				"5I", "5Q", "5X",  // 22-24    // E5A
				"",                         // 25
				"", "", "", "", "", "", "", //26-32
			}
		  GAL Signal ID: E1BC=0, E5A=1, E5B=2, E6=3, ALTBOC=4
	*/

	HEMI_GAL_SIGN_YOBS_MAP = []byte{YOBS_GAL_SIGN_E1_1C, YOBS_GAL_SIGN_E5A_5Q, YOBS_GAL_SIGN_E5B_7Q, YOBS_GAL_SIGN_E6_6C, 0}

	//YOBS_GPS_SIGN_MAP = []string{
	//	"",   // 1
	//	"1C", "1P", "1W", // 2, 3, 4    L1
	//	"", "", "", //
	//	"2C", "2P", "2W", // 8, 9, 10   L2
	//	"", "", "", "",   // 11-14
	//	"2S", "2L", "2X", // 15-17     L2
	//	"", "", "", "",   // 18-21
	//	"5I", "5Q", "5X", // 22-24     L5
	//	"", "", "", "", "", // 25 -29
	//	"1S", "1L", "1X", //30-32    // L1
	//}
	// GPS Signal ID: L1CA=0, L2P=1, L2C=2, L5=3
	HEMI_GPS_SIGN_YOBS_MAP = []byte{YOBS_GPS_SIGN_L1_1C, YOBS_GPS_SIGN_L2_2W, YOBS_GPS_SIGN_L2_2S, YOBS_GPS_SIGN_L5_5Q}

	/***
		YOBS_QZS_SIGN_MAP = []string{"",
		"1C", "", "", // 2, 3, 4    L1
		"", "", "", "", // 5,6,7, 8
		"6S", "6L", "6X", // 9, 10 11    LEX
		"", "", "", // 12-14
		"2S", "2L", "2X", // 15-17     L2  (L2C(M), L2C(L), L2C(M+L))
		"", "", "", "", // 18-21
		"5I", "5Q", "5X", // 22-24     L5
		"", "", "", "", "", // 25 -29
		"1S", "1L", "1X", //30-32    // L1
	   }
		QZS Signal ID: L1CA=0, L2C=2, L5=3, L1C=4
	*/
	HEMI_QZS_SIGN_YOBS_MAP = []byte{YOBS_QZX_SIGN_1C, 0, YOBS_QZX_SIGN_2X, YOBS_QZX_SIGN_5Q, YOBS_QZX_SIGN_1S}

	/**
	YOBS_GLO_SIGN_MAP = []string{
		"",    // 1
		"1C", "1P", "",  // 2,3,4
		"", "", "",      // 5,6,7
		"2C", "2P", "",  // 8,9,10
		"", "", "",      // 11,12,13
		"", "", "", "", "", "", "", "", "", "", "", "", // 14-25
		"", "", "", "", "", "", "", //26-32
	}
	GLO Signal ID: G1C/G1P=0, G2C/G2P=1, G10C=4, G20C=5, G30C=6
	*/
	HEMI_GLO_SIGN_YOBS_MAP = []byte{3, 9}

	HEMI_GLO_SIGTYPE_YOBS_MAP = []byte{SIG_TYPE_GLO_G1, SIG_TYPE_GLO_G2}
	HEMI_GLA_SIGTYPE_YOBS_MAP = []byte{SIG_TYPE_GAL_E1, SIG_TYPE_GAL_E5A, SIG_TYPE_GAL_E5B, SIG_TYPE_GAL_E6, SIG_TYPE_GAL_E5AB}
	HEMI_BDS_SIGTYPE_YOBS_MAP = []byte{SIG_TYPE_BDS_B1I, SIG_TYPE_BDS_B2I, SIG_TYPE_BDS_B3I, SIG_TYPE_BDS_B1C, SIG_TYPE_BDS_B2A, SIG_TYPE_BDS_B2B, SIG_TYPE_BDS_B3C, SIG_TYPE_BDS_B2AB}
	HEMI_QZS_SIGTYPE_YOBS_MAP = []byte{SIG_TYPE_QZS_L1, 0, SIG_TYPE_QZS_L2, SIG_TYPE_QZS_L5, SIG_TYPE_QZS_L1}
)

//func HemiSignalStr(naviSys byte, id byte) string {
//
//	var HEMI_GPS_SIGNAL = []string{"1C", "2P", "2C", "L5"}
//
//	switch naviSys {
//	case SYS_GPS:
//		if int(id) < len(HEMI_GPS_SIGNAL) {
//			return HEMI_GPS_SIGNAL[id]
//		}
//	}
//
//	return "NN"
//}

/**
// Array of 16, 16 bit words (32 bytes)
                                                //[15,14]  spare bits
                                                //[13] = 1 if GLONASS P-Code
                                                //[12,11,10,9,8] = Channel (0 is the first channel)
                                                //[7,6,5,4] = Signal ID (L1CA, L5, G1, B1I, B2I, B3I, etc)
                                                // GPS Signal ID: L1CA=0, L2P=1, L2C=2, L5=3
                                                // GLO Signal ID: G1C/G1P=0, G2C/G2P=1, G10C=4, G20C=5, G30C=6
                                                // GAL Signal ID: E1BC=0, E5A=1, E5B=2, E6=3, ALTBOC=4
                                                // BDS Signal ID: B1I=0, B2I=1, B3I=2,B1BOC=3,B2A=4,B2B=5,B3C=6,ACEBOC=7
                                                // QZS Signal ID: L1CA=0, L2C=2, L5=3, L1C=4
                                                //[3,2,1,0] = GNSS System, 0=GPS,1=GLO,2=GAL,3=BDS,4=QZS
*/

var (
	HEMI_GPS_SIGN_GNSSSV_MAP = []byte{GNSS_SV_SIG_GPS_L1_1C, GNSS_SV_SIG_GPS_L2_2W, GNSS_SV_SIG_GPS_L2_2S, GNSS_SV_SIG_GPS_L5_5Q}
	HEMI_GLO_SIGN_GNSSSV_MAP = []byte{GNSS_SV_SIG_GLO_G1_1P, GNSS_SV_SIG_GLO_G2_2P}
	HEMI_GAL_SIGN_GNSSSV_MAP = []byte{GNSS_SV_SIG_GAL_E1_1C, GNSS_SV_SIG_GAL_E5a_5Q, GNSS_SV_SIG_GAL_E5b_7Q, GNSS_SV_SIG_GAL_E6_6C, 0}
	HEMI_QZS_SIGN_GNSSSV_MAP = []byte{GNSS_SV_SIG_QZS_L1_1C, 0, GNSS_SV_SIG_QZS_L2_2X, GNSS_SV_SIG_QZS_L5_5Q, GNSS_SV_SIG_QZS_L1_1S}

	// BDS Signal ID:
	//    B1I=2I,
	//    B2I=7I,
	//    B3I=6I,
	//    B1BOC=1P,
	//    B2A=5P,  5D
	//    B2B=7P,  7D
	//    B3C=预留,
	//    ACEBOC=8P
	//
	HEMI_BDS_SIGN_GNSSSV_MAP = []byte{GNSS_SV_SIG_BDS_B1_2I, GNSS_SV_SIG_BDS_B2_7I, GNSS_SV_SIG_BDS_B3_6I, GNSS_SV_SIG_BDS_B1C_1P,
		GNSS_SV_SIG_BDS_B2a_5D, GNSS_SV_SIG_BDS_B2b_7D, 0, GNSS_SV_SIG_BDS_B2ab_8P}
)

func HemiSigId2GnssSVSigId(naviSys byte, extype byte, srcSigId byte) (sigid byte) {
	sig := srcSigId
	if naviSys == SYS_GPS || naviSys == SYS_SBS {
		if int(sig) < len(HEMI_GPS_SIGN_GNSSSV_MAP) {
			sigid = HEMI_GPS_SIGN_GNSSSV_MAP[sig]
		}
	} else if naviSys == SYS_GLO {
		if sig == 0 {
			if extype == 1 { // 1 if GLONASS P-Code
				return GNSS_SV_SIG_GLO_G1_1P
			} else {
				return GNSS_SV_SIG_GLO_G1_1C
			}
		} else if sig == 1 {
			if extype == 1 { // 1 if GLONASS P-Code
				return GNSS_SV_SIG_GLO_G2_2P
			} else {
				return GNSS_SV_SIG_GLO_G2_2C
			}
		}

		if int(sig) < len(HEMI_GLO_SIGN_GNSSSV_MAP) {
			sigid = HEMI_GLO_SIGN_GNSSSV_MAP[sig]
		}
	} else if naviSys == SYS_GAL {
		if int(sig) < len(HEMI_GAL_SIGN_GNSSSV_MAP) {
			sigid = HEMI_GAL_SIGN_GNSSSV_MAP[sig]
		}
	} else if naviSys == SYS_QZS {
		if int(sig) < len(HEMI_QZS_SIGN_GNSSSV_MAP) {
			sigid = HEMI_QZS_SIGN_GNSSSV_MAP[sig]
		}
	} else if naviSys == SYS_BD {
		if int(sig) < len(HEMI_BDS_SIGN_GNSSSV_MAP) {
			sigid = HEMI_BDS_SIGN_GNSSSV_MAP[sig]
		}

	}

	return
}
